package com.bicon.botu.mall.order;

import com.bicon.botu.core.base.annotation.*;
import com.bicon.botu.core.base.config.SystemInterceptor;
import com.bicon.botu.mall.order.websocket.WebSocketServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 应用启动类
 *
 * @author 谈东魁
 * @date 2017/7/16 下午 21:56
 */
@SpringBootApplication
@EnableGlobalRedis
@EnableMyBatisPlusConfig // MyBatis配置
@MapperScan("com.bicon.botu.mall.order.mapper") //扫描mapper
@EnableHttpLogAspect //http请求日志
@EnableGlobalExceptionHandler //统一异常处理
//系统拦截器
@EnableSystemInterceptor
//@EnableElasticJob
public class OrderApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args){
        SpringApplication springApplication = new SpringApplication(OrderApplication.class);
        ConfigurableApplicationContext applicationContext =  springApplication.run(args);
        WebSocketServer.setApplicationContext(applicationContext);
    }

    @Bean
    public SystemInterceptor getMyInterceptor(){
        return new SystemInterceptor();
    }

    /**
     * 配置拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor()).addPathPatterns("/**");
    }

}
